<template>
	<view class="volunteerInfo">
		<view class="top">
			<view class="line" @click="jump('forceDetail', 'type=grade_money')">
				总佣金：￥<text>{{info.gradeMoney}}</text>
			</view>
			<view class="line">
				推广会员数：<text>{{info.childNum}}</text>
			</view>
		</view>
		<scroll-view scroll-y="true" class="listScroll" lower-threshold="50" @scrolltolower="getList()">
			<view class="list_item" v-for="(item,index) in listData.list" :key="index" @click="jump(selType == 'goods' ? 'product_view' : 'card_view', item.id)">
				<image :src="item.head_portrait" mode=""></image>
				<view class="item_info">
					<view class="title">{{item.username}}（{{item.mobile}}）</view>
					<view class="typeName">{{item.type_name}}</view>
					<view class="info">
						<view class="branch" v-for="(item2, index2) in item.valList" :key="index2">
							<view class="branchTitle">{{item2.title}}</view>
							<view class="branchVal">{{item2.val}}</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="bot" @click="showPreviewpup()">推广海报</view>
		
		<uni-popup ref="previewpup" type="center">
			<view class="popbox">
				<swiper v-if="info.shareList && info.shareList.length>0"
					class="swiper" 
					duration="500" 
					:circular="false" 
					:skip-hidden-item-layout="true" 
					:disable-programmatic-animation="true" 
					@change="swiperChange" 
					>
					<swiper-item  class="swiper-item" v-for="(itemImg,index) in info.shareList"  :key="index" :item-id="'swiper-item-' + index" >
						<view class="imagebox">	
							<image mode="widthFix" 
								:lazy-load="true" 
								:src="itemImg.max" 
								:data-src="itemImg.src" 
								
							/>
						</view>
					</swiper-item>
				</swiper>
					<!-- 当前序号和张数 -->
				<view class="maskpagesize">
					<text>
						{{nowCurrent * 1 + 1 * 1}}/{{info.shareList.length}}
					</text>
				</view>
				
				<!-- 状态标识 -->
				<view class="maskshowrev">
				    <button class="btall bt2" open-type="share" @click="shareFun(1)">
				        <uni-icons type="weixin" color="#ccc" size="15"></uni-icons>
				        <text>发送给好友</text>
				    </button>
					<button class="btall bt2" open-type="share" @click="shareFun(2)">
					    <uni-icons type="staff" color="#ccc" size="15"></uni-icons>
					    <text>分享到朋友圈</text>
					</button>
					<button class="btall bt3" @click="shareFun(3)">
					    <uni-icons type="pulldown" color="#ccc" size="15"></uni-icons>
					    <text>下载</text>
					</button>
					<button class="btall bt1" @click="shareFun(4)">
					    <uni-icons type="close" color="#ccc" size="15"></uni-icons>
					    <text>关闭</text>
					</button>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import serve from '../../static/request.js';
	import common from '../../static/jump.js';
	import ShareIndex from '../../static/share.js';
	
	export default {
		mixins: [ShareIndex],
		data() {
			return {
				info: {
					childNum: 0,
					gradeMoney: 0.00,
					shareList: [],
				},
				shareSrc: [],
				nowCurrent: 0,
				listParam: {
					page: 0,
					pageSize: 10,
				},				
				listData: {  
					list: [],
					isEmpty: false,
					isEnd: false
				},
				shareType: 1,
				shareItem: {},
			}
		},
		methods: {
			showPreviewpup() {
				this.$refs.previewpup.open();  
			},
			swiperChange: function(e) {
				console.info("swiperChange", e);
				this.nowCurrent = e.detail.current;
			},
			moretap: function(e){
				console.info("moretap", e);
			},
			shareFun(type) {
				var imgUrl = this.shareSrc[this.nowCurrent];
				this.shareItem.title = "龙鳞黄";
				this.shareItem.path = '/pages/index/index?shanhaiKey='+uni.getStorageSync('shanhaiKey');
				this.shareItem.linePaht = '/pages/index/index';
				this.shareItem.query = 'shanhaiKey='+uni.getStorageSync('shanhaiKey');
				this.shareItem.imageUrl = imgUrl;
				if(type == 1 || type == 2) {
					this.shareType == type;
					return ;
				}
				if(type == 3) {
					uni.showModal({
						title: '提示',
						content: '确定要下载海报到您的相册吗',
						success: function (res) {
							if (res.confirm) {
								uni.downloadFile({
									url: imgUrl,
									success: (res) =>{
										if (res.statusCode === 200){
											uni.saveImageToPhotosAlbum({
												filePath: res.tempFilePath,
												success: function() {
													uni.showToast({
														title: "保存成功",
														icon: "none"
													});
												},
												fail: function() {
													uni.showToast({
														title: "保存失败",
														icon: "none"
													});
												}
											});
										} 
									},
									fail: function() {
										uni.showToast({
											title: "保存失败2",
											icon: "none"
										});
									}
								})
							} 
						}
					});
				}
				if(type == 4) {
					this.$refs.previewpup.close();
				}
			},
			previewpics(){
				var self = this;
				uni.previewImage({
					current: this.nowCurrent,
					urls: this.shareSrc,
					showmenu: true,
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '下载'],
						success: function(data) {
							let index = data.tapIndex * 1 + 1 * 1;
							self.shareFun(index)
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				})
			},
			getInfo() {
				var self = this;
				serve.request({
					url: '/member/promotion/info',
					data: {}
				}).then(res => {
					if(res.code == 200) {
						this.info = res.data;
						this.shareSrc = [];
						this.info.shareList.forEach((i, k) => {
							this.shareSrc.push(i.src);
						})
					} else {
						uni.showToast({
							title:res.message,
							icon: 'none',
							success() {
								setTimeout(function () {
									common.jump('my')
								}, 2000) 
							}
						})
					}
				});
			},
			getList() {
				if(this.listData.isEnd) {
				    return ;
				}
				this.listParam.page++;
				uni.showLoading({
				    title: '加载中',
				    mask: true
				});
				serve.request({
				    url: '/member/promotion/list',
				    data: this.listParam
				}).then(res => {
				    if (res.data && res.data.length > 0) {
				        this.listData.list = this.listData.list.concat(res.data);
				    } 
					this.listData.isEnd = res.data.length < this.listParam.pageSize ? true : false;
				});
			},
			jump(jump_type, jump_link){
				common.jump(jump_type, jump_link);
			}
		},
		onLoad(options) {
			this.getInfo();
			this.getList();
		},
		onPullDownRefresh() {
			this.getInfo();
			this.getList();
		},
		onShareAppMessage() {
			console.info(this.shareItem);
		    if (this.shareType === 'friend') {
				return this.shareItem;
		    }
		},
		onShareTimeline() {
		    if (this.shareType === 'timeline') {
				return this.shareItem;
		    }
		}
	}
</script>

<style scoped lang="scss">
	.volunteerInfo {
		width: 100%;
		padding-bottom: 100upx;

		.top {
			padding: 30upx;
			border-bottom: 16upx #FBFBFD solid;
			display: flex;
			.line {
				width: 50%;
			}
			text{
				color: red;
				font-size: 40rpx;
			}
		}
		
		.listScroll {
			height: calc(100vh - 250rpx);
			padding: 10rpx 30rpx;
			.list_item {
				width: 90%;
				padding-bottom: 16rpx;
				display: flex;
				padding: 8rpx;
				border: 1rpx solid #ccc;
				margin-bottom: 8rpx;
				border-radius: 14rpx;
				image {
					width: 150rpx;
					height: 150rpx;
					border-radius: 2%;
				}
				.item_info {
					width: calc(100% - 160rpx);
					height: 150rpx;
					padding-left: 10rpx;
					font-size: 28rpx;
					color: #333;
					position: relative;
				}
				.title {
					height: 40rpx;
					overflow: hidden;
					text-overflow: -o-ellipsis-lastline;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
				}
				.typeName {
					font-size: 26rpx;
					color: #1a0ed6;
					position: absolute;
					right: 10rpx;
					top: 0rpx;
				}
				.info {
					display: flex;
					text-align: center;
					margin-top: 14rpx;
				}
				.branch {
					width: 48%;
					border: 1rpx solid #eee;
					border-radius: 20rpx;
					margin-right: 1%;
					padding: 6rpx;
				}
				.branchTitle {
					padding-bottom: 10rpx;
				}
			}
		}
		.bot{
			position: fixed;
			bottom: 0;
			height:100upx;
			line-height: 100upx;
			text-align: center;
			background:rgba(255,198,0,1);
			width: 100%;
			font-size:32upx;
			color:rgba(255,255,255,1);
			border-radius: 10rpx;
		}
		
		.popbox{
			width: 100vw;
			height: 100vh;
			//background-color: #333;
			display: flex;
			flex-direction: column; 
			justify-content: flex-start;
			align-items: center;
			padding-bottom: 140upx;
			position: relative;
			
			.swiper{
				width: 100%; 
				height: 100%;
				min-height: 500upx;
				position: absolute;
				top:0upx;
				left:0upx;
				
				.swiper-item{
					width: 100%; 
					height: 100%;
					min-height: 500upx;
					padding-bottom: 120upx;
					background-color: rgba(#000,0.8);
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					
					.imagebox{
						width: 100%;
						height: auto;
						min-height: 300upx; 
						background-size: 20% auto;
						background-position: center center;
						
						image{
							width: 100%;
							height: auto;
						}
					}
				}
			}
	
	.maskshowrev {
		width: 100%;
		height: 50upx;
		bottom: 250upx;
		position: fixed;
		display: flex;
		justify-content: space-around;
		
		//border: 1upx #fff solid;
		.btall {
			height: 50upx;
			border-radius: 25upx;
			padding: 0 20upx;
			color: #Fff;
			font-size: 24upx;
			line-height: 50upx;
			font-weight: normal;
			text-align: center; 
		}
		
		.bt1 {background-color: rgba(#780000, 0.9);}
		.bt2 {background-color: rgba(#7bc9d3, 0.9);}
		.bt3 {background-color: rgba(#ffcc00, 0.9);}
	}
	
	.maskpagesize{
		width: 150upx;
		height: 50upx;
		
		position: fixed;
		left: 300upx;
		bottom: 350upx; 
		
		display: flex;
		justify-content: center;
		//background-color: #ffcc00;
		text{
			color: #fff;
			font-size: 40upx;
			font-weight: 200;
			line-height: 50upx;
			text-align: center;
			text-shadow: 0upx 0upx 5upx rgba(#000, 1);
		}
	}
		}
	}
</style>
